package com.gofunbuy.app.store;

import java.util.List;

import com.gofunbuy.R;
import com.gofunbuy.core.ProductEntity;
import com.gofunbuy.core.ReceiptEntity;
import com.gofunbuy.util.AsyncImageLoader;
import com.gofunbuy.util.AsyncImageLoader.ImageCallback;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class ReceiptAdapter extends BaseAdapter {

	private LayoutInflater mInflater;
	private List<ReceiptEntity> mData;

	public ReceiptAdapter(Context context) {
		this.mInflater = LayoutInflater.from(context);
	}

	public void setDatas(List<ReceiptEntity> data) {
		mData = data;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		if (mData == null) {
			return 0;
		}
		return mData.size();
	}

	@Override
	public ReceiptEntity getItem(int arg0) {
		// TODO Auto-generated method stub
		return mData.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder = null;
		if (convertView == null) {

			holder = new ViewHolder();

			convertView = mInflater.inflate(R.layout.receipt_item_layout, null);
			
			holder.name = (TextView) convertView
					.findViewById(R.id.receipt_item_name);
			holder.price = (TextView) convertView
					.findViewById(R.id.receipt_item_price);
			holder.donation = (TextView) convertView
					.findViewById(R.id.receipt_item_donation);
			holder.date = (TextView) convertView
					.findViewById(R.id.receipt_item_date);
			convertView.setTag(holder);

		} else {

			holder = (ViewHolder) convertView.getTag();
		}
		ReceiptEntity pe = mData.get(position);

		holder.name.setText(pe.getName());
		holder.price.setText("HK$" + pe.getPrice());
		holder.donation.setText(pe.getDonation());
		holder.date.setText(pe.getDate());
		return convertView;
	}

	public final class ViewHolder {

		public TextView name;
		public TextView price;
		public TextView donation;
		public TextView date;
	}
}